﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using kim.Common;
using System.Data;

namespace kim.UI
{
    public class ManagePage : System.Web.UI.Page
    {

        
        public ManagePage()
        {
            //this.Load += new EventHandler(ManagePage_Load);

        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ManagePage_Load();
           
        }
        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="rep_x">Repeater控件ID</param>
        /// <param name="Tbname">控件表名</param>
        /// <param name="order">排序</param>
        /// <param name="Pwhere">筛选</param>
        /// <param name="Cwhere">总数条件</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="StrUrl">当前页面</param>
        /// <param name="cenSize">中间页码数量</param>
        /// <param name="StrPage">返回页HTML</param>
        public void GetStrPage(Repeater rep_x, string Tbname,string order,string Cwhere,string Pwhere, int pageIndex, int pageSize,string StrUrl,int cenSize,out string StrPage)
        {
            int count=0;
            kim.BLL.Show bll = new BLL.Show();
            count = SqlDbHelper.GetPageCurrent(Tbname, Cwhere);
            using (DataSet dt = bll.GetNewsPager(pageIndex, pageSize, "", order, Pwhere))
            {
                rep_x.DataSource = dt;
                rep_x.DataBind();
            }
            StrPage = kim.Common.Utils.OutPageList(pageSize, pageIndex, count, StrUrl + "?p=__id__", cenSize);
        }
        protected void ManagePage_Load()
        {
            BLL.siteconfig bll = new BLL.siteconfig();
            Model.siteconfig model = bll.loadConfig(Utils.GetXmlMapPath(KIMKeys.FILE_SITE_XML_CONFING));
            //判断管理员是否登录
            if (!IsAdminLogin())
            {
                Response.Write("<script>parent.location.href='/" + model.webmanagepath + "/login.aspx'</script>");
                Response.End();
            }
        }

        #region 管理员============================================
        /// <summary>
        /// 判断管理员是否已经登录(解决Session超时问题)
        /// </summary>
        public bool IsAdminLogin()
        {
            //如果Session为Null
            if (Session[KIMKeys.SESSION_ADMIN_INFO] != null)
            {
                return true;
            }
            else
            {
                //检查Cookies
                string adminname = Utils.GetCookie("AdminName", "KIM"); //解密用户名
                string adminpwd = Utils.GetCookie("AdminPwd", "KIM");
                if (adminname != "" && adminpwd != "")
                {
                    BLL.eg_Admin bll = new BLL.eg_Admin();
                    Model.eg_Admin model = bll.GetModel(adminname, adminpwd);
                    if (model != null)
                    {
                        Session[KIMKeys.SESSION_ADMIN_INFO] = model;
                        return true;
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 取得管理员信息
        /// </summary>
        public Model.eg_Admin GetAdminInfo()
        {
            if (IsAdminLogin())
            {
                Model.eg_Admin model = Session[KIMKeys.SESSION_ADMIN_INFO] as Model.eg_Admin;
                if (model != null)
                {
                    return model;
                }
            }
            return null;
        }

        ///// <summary>
        ///// 检查管理员权限
        ///// </summary>
        ///// <param name="channel_id">频道ID</param>
        ///// <param name="action_type">操作类型</param>
        //public void ChkAdminLevel(int channel_id, string action_type)
        //{
        //    Model.manager model = GetAdminInfo();
        //    BLL.Manager_log bll = new BLL.manager_role();
        //    bool result = bll.Exists(model.role_id, channel_id, action_type);
        //    if (!result)
        //    {
        //        string msbox = "parent.f_errorTab(\"错误提示\", \"您没有管理该页面的权限，请勿尝试非法进入！\")";
        //        //ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox.ToString(), true);  //修正BUG
        //        Response.Write("<script type=\"text/javascript\">" + msbox + "</script>");
        //        Response.End();
        //    }
        //}

        ///// <summary>
        ///// 检查管理员权限
        ///// </summary>
        ///// <param name="channel_name">栏目名称</param>
        ///// <param name="action_type">操作类型</param>
        //public void ChkAdminLevel(string channel_name, string action_type)
        //{
        //    Model.manager model = GetAdminInfo();
        //    BLL.manager_role bll = new BLL.manager_role();
        //    bool result = bll.Exists(model.role_id, channel_name, action_type);
        //    if (!result)
        //    {
        //        string msbox = "parent.f_errorTab(\"错误提示\", \"您没有管理该页面的权限，请勿尝试非法进入！\")";
        //        //ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox.ToString(), true);  //修正BUG
        //        Response.Write("<script type=\"text/javascript\">" + msbox + "</script>");
        //        Response.End();
        //    }
        //}

        ///// <summary>
        ///// 检查管理员权限
        ///// </summary>
        ///// <param name="channel_name">栏目名称</param>
        ///// <param name="action_type">操作类型</param>
        ///// <returns>bool</returns>
        //public bool IsAdminLevel(string channel_name, string action_type)
        //{
        //    Model.manager model = GetAdminInfo();
        //    BLL.manager_role bll = new BLL.manager_role();
        //    return bll.Exists(model.role_id, channel_name, action_type);
        //}

        #endregion



    }
}
